package svn;

import org.tmatesoft.svn.core.*;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
import org.tmatesoft.svn.core.wc.*;

import java.io.File;

public class SVNAddUnversionedFiles {
    public static void main(String[] args) {

        // 本地SVN仓库路径
        File repositoryFile = new File("C:\\Datas\\E9\\客户分支\\S深圳市卡司通展览股份");

        // 设置身份验证信息，如果需要的话
        ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager("shxl2021", "ff8d7o0rmc2j7");

        try {

            // 创建SVNClientManager实例
            SVNClientManager clientManager = SVNClientManager.newInstance((ISVNOptions) null, authManager);

            // 获取本地状态信息
            SVNStatusClient statusClient = clientManager.getStatusClient();
            statusClient.doStatus(repositoryFile, SVNRevision.BASE, SVNDepth.INFINITY, false, false, true, false,
                    new ISVNStatusHandler() {
                        @Override
                        public void handleStatus(SVNStatus status) throws SVNException {
                            // 获取未受版本控制的文件
                            if (status.getContentsStatus() == SVNStatusType.STATUS_NONE) {
                                // 添加未被版本控制的文件到SVN
                                clientManager.getWCClient().doAdd(status.getFile(), false, false, false, SVNDepth.INFINITY, false, false, true);
                                System.out.println("Added: " + status.getFile());
                            }
                        }
                    }, null);

        } catch (SVNException e) {
            e.printStackTrace();
        }
    }

    private static void setupLibrary() {
        // 初始化SVN库
        DAVRepositoryFactory.setup();
        SVNRepositoryFactoryImpl.setup();
        FSRepositoryFactory.setup();
    }
}
